<%@ page import="java.net.URLDecoder" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<base href="<%=basePath%>">
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layui/css/layui.css" media="all">
</head>
<body>
<br><br>
<form class="layui-form" action="" method="">

    <div class="layui-form-item">
        <label class="layui-form-label">ID</label>
        <div class="layui-input-block">
            <input type="text" name="id" style="width:200px;" autocomplete="off" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="freelance_name" style="width:200px;" autocomplete="off" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">电话</label>
        <div class="layui-input-block">
            <input type="text" name="freelance_tel" style="width:200px;" autocomplete="off" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
            <input type="text" name="freelance_email" style="width:200px;" autocomplete="off" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">地址</label>
        <div class="layui-input-block">
            <input type="text" name="freelance_address" style="width:200px;" autocomplete="off" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
            <input type="text" name="freelance_type" style="width:200px;" autocomplete="off" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="demo1" type="button">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script src="layui/layui.js"></script>
<script>
    //JavaScript代码区域
    layui.use('element', function(){
        var element = layui.element;
    });
    layui.use(['form'], function () {
        var form = layui.form;
        var $ = layui.$;

        form.on('submit(demo1)', function (data) {
            var data1 = {
                'freelance_id':data.field.id,
                'freelance_name':data.field.freelance_name,
                'freelance_tel':data.field.freelance_tel,
                'freelance_email':data.field.freelance_email,
                'freelance_address':data.field.freelance_address,
                'freelance_type':data.field.freelance_type
            }
            //layer.msg(JSON.stringify(data1));
            $.ajax({
                url: "${pageContext.request.contextPath}/freelance/insertFreelance",
                type: "post",
                dataType: "json",
                data:JSON.stringify(data1),
                //contentType: false,
                contentType:'application/json;charset=utf-8',
                success: function (res) {
                    //var json=JSON.parse(res);
                    if (res.code == "0") {
                        layer.msg("添加成功！",{icon: 6});
                        parent.location.reload();
                    } else {
                        layer.msg("添加失败！",{icon: 5});//失败的表情
                    }
                }
            });
        });
        return false;
    });
</script>
</body>
</html>
